package com.study.springboot.service.impl;

import com.study.springboot.dao.DepartRepository;
import com.study.springboot.dto.Depart;
import com.study.springboot.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huyong
 * @Decription
 * @date 2025-03-05 14:50
 */
@Service
public class DepartServiceImpl implements DepartService {
    @Autowired
    private DepartRepository departRepository;

    @Override
    public boolean saveDepart(Depart depart) {
        departRepository.save(depart);
        return true;
    }

    @Override
    public boolean deleteDepartById(Integer id) {
        if (departRepository.existsById(id)) {
            departRepository.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean modifyDepart(Depart depart) {
        departRepository.save(depart);
        return true;
    }

    @Override
    public Depart getDepartById(Integer id) {
        return departRepository.findById(id).orElse(new Depart());
    }

    @Override
    public List<Depart> getAllDeparts() {
        return departRepository.findAll();
    }
}
